<template>
  <div style="height:150px">
    <el-select v-model="value"
               placeholder="请选择要投诉的小区">
      <el-option v-for="item in options"
                 :key="item.value"
                 :label="item.label"
                 :value="item.value">
      </el-option>
    </el-select>
    <br><br>
    <el-input v-model="content"
              placeholder="请输入投诉内容">
    </el-input>

    <div id="action">
      <el-button type="success"
                 @click="cancle">取 消</el-button>
      <el-button type="primary"
                 @click="commit">确 定</el-button>
    </div>
  </div>
</template>

<script>
import http from '../../../../axios_config';
export default {

  data () {
    return {
      options: [],
      value: '',
      content: ''
    }
  },
  methods: {
    getCommunity () {
      http.get("http://192.168.11.18:8080/community/findUserCommunity")
        .then(res => {
          console.log(res.data.data);
          let communitys = [];
          if (res.data.statusCode == "200") {
            this.options = [];
            for (let i = 0; i < res.data.data.length; i++) {
              this.options[i] = {
                label: res.data.data[i].name,
                value: res.data.data[i].id
              }
            }
          }
        });
    },
    //确定投诉
    commit () {
      let data = {
        content: this.content,
        label: this.value
      }
      console.log(data);
      this.$emit("closeinsert", { result: true, data: data })
    },
    //取消投诉
    cancle () {
      this.$emit("closeinsert", { result: false, data: {} })
    }
  },
  mounted () {
    console.log("投诉界面生成");
    this.getCommunity();

    // //获取所有可以投诉的小区
    // let communitys = [];
    // communitys = this.getCommunity();
    // console.log(this.getCommunity());
    // for (let i = 0; i < communitys.length; i++) {
    //   let key = i;
    //   let value = communitys[i].name;
    //   this.options.push(key, value);
    // }

  }
}
</script>

<style scoped>
#action {
  position: absolute;
  right: 10px;
  bottom: 10px;
}
</style>